package pro.cherish.knowledgeutil.io;

import java.io.File;
import java.io.FileFilter;
import java.util.regex.Pattern;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-11-01 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：FileFilterUtilExt
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-11-01 cherish
 */
public class FileFilterUtilExt {

    private FileFilterUtilExt() {
    }

    public static FileFilter prefixFileFilter(final String... prefixes) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                String[] var2 = prefixes;
                int var3 = var2.length;

                for(int var4 = 0; var4 < var3; ++var4) {
                    String prefix = var2[var4];
                    if (pathname.getName().startsWith(prefix)) {
                        return true;
                    }
                }

                return false;
            }
        };
    }

    public static FileFilter suffixFileFilter(final String... suffixes) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                String[] var2 = suffixes;
                int var3 = var2.length;

                for(int var4 = 0; var4 < var3; ++var4) {
                    String suffix = var2[var4];
                    if (pathname.getName().endsWith(suffix)) {
                        return true;
                    }
                }

                return false;
            }
        };
    }

    public static FileFilter nameFileFilter(final String name) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.getName().equals(name);
            }
        };
    }

    public static FileFilter regexFileFile(final String regex) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return Pattern.matches(regex, pathname.getPath());
            }
        };
    }

    public static FileFilter directoryFileFilter() {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        };
    }

    public static FileFilter notDirectoryFileFilter() {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return !pathname.isDirectory();
            }
        };
    }

    public static FileFilter sizeLtFileFilter(final long size) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.length() < size;
            }
        };
    }

    public static FileFilter sizeGtFileFilter(final long size) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.length() > size;
            }
        };
    }

    public static FileFilter sizeEqualFileFilter(final long size) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.length() == size;
            }
        };
    }

    public static FileFilter and(final FileFilter... filters) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                boolean result = true;
                FileFilter[] var3 = filters;
                int var4 = var3.length;

                for(int var5 = 0; var5 < var4; ++var5) {
                    FileFilter filter = var3[var5];
                    if (filter != null) {
                        result = result && filter.accept(pathname);
                    }
                }

                return result;
            }
        };
    }

    public static FileFilter or(final FileFilter... filters) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                boolean result = false;
                FileFilter[] var3 = filters;
                int var4 = var3.length;

                for(int var5 = 0; var5 < var4; ++var5) {
                    FileFilter filter = var3[var5];
                    result = result || filter.accept(pathname);
                }

                return result;
            }
        };
    }

    public static FileFilter not(final FileFilter filter) {
        return new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return !filter.accept(pathname);
            }
        };
    }
}
